package com.ssh.web.caction;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.entity.Staff;
import com.ssh.model.ddata.MStaff;
import com.ssh.ser.common.ProfileEditService;
import com.ssh.ser.comonstaff.StaffServiceI;

public class StaffEditProfileAction extends ActionSupport {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private String address;
	private String education;
	private String email;
	private String firstName;
	private String lastName;
	private String marriage;
	private String politicsState;
	private ProfileEditService profileEditService;
	private StaffServiceI staffService;
	private Staff staff;
	private String staffId;

	private Long staffTel;

	public StaffServiceI getStaffService() {
		return staffService;
	}

	public void setStaffService(StaffServiceI staffService) {
		this.staffService = staffService;
	}

	public String editProfile() {
		if (staff != null){
			Staff s = (Staff) ServletActionContext.getContext().getSession().get("staff");
			s.setAddress(staff.getAddress());
			s.setLastName(staff.getLastName());
			s.setFirstName(staff.getFirstName());
			s.setPoliticsState(staff.getPoliticsState());
			s.setMarriage(staff.getMarriage());
			s.setEmail(staff.getEmail());
			s.setEducation(staff.getEducation());
			staffService.updateStaffInfo(s);
			return "ok";
		}
		if (staff==null) staff = (Staff) ServletActionContext.getContext().getSession()
				.get("staff");
		
		return "error";
	}

	public String getAddress() {
		return address;
	}

	/**
	 * @return the education
	 */
	public String getEducation() {
		return education;
	}

	public String getEmail() {
		return email;
	}

	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}

	/**
	 * @return the marriage
	 */
	public String getMarriage() {
		return marriage;
	}

	/**
	 * @return the politicsState
	 */
	public String getPoliticsState() {
		return politicsState;
	}

	public ProfileEditService getProfileEditService() {
		return profileEditService;
	}

	/**
	 * @return the staff
	 */
	public Staff getStaff() {
		return staff;
	}

	public String getStaffId() {
		return staffId;
	}

	public Long getStaffTel() {
		return staffTel;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @param education
	 *            the education to set
	 */
	public void setEducation(String education) {
		this.education = education;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @param marriage
	 *            the marriage to set
	 */
	public void setMarriage(String marriage) {
		this.marriage = marriage;
	}

	/**
	 * @param politicsState
	 *            the politicsState to set
	 */
	public void setPoliticsState(String politicsState) {
		this.politicsState = politicsState;
	}

	public void setProfileEditService(ProfileEditService profileEditService) {
		this.profileEditService = profileEditService;
	}

	/**
	 * @param staff
	 *            the staff to set
	 */
	public void setStaff(Staff staff) {
		this.staff = staff;
	}

	public void setStaffId(String staffId) {
		this.staffId = staffId;
	}

	public void setStaffTel(Long staffTel) {
		this.staffTel = staffTel;
	}

	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try{
			editProfile();
			return "ok";
		}
		catch(Exception e){
			return "error";
		}

	}

}
